﻿using Base.ClientUI;
using MathWorks.MATLAB.NET.Arrays;
using myPolt33;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace HY.WCS.Client.Frames {
    public partial class EqupFrm : Form {
        MatlabDll matlabPolt3 =null;
       public Main supper = null;
        public EqupFrm() {
            InitializeComponent();
            dataGridView1.Columns.Add(new DataGridViewCheckBoxColumn());
            AddColumn("名称", "className").AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
            AddColumn("间隔", "time").AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
            AddColumn("次数", "workCount").AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
            AddColumn("占比", "ppm").AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
            AddColumn("执行总时间", "workAllTime").AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
            AddColumn("最近执行时间", "worklastTime").AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
            AddColumn("最长时间", "maxTime").AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
            AddColumn("最短时间", "minTime").AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
            AddColumn("平均", "avg").AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
            AddColumn("异常", "exceptionCount").AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
            dataGridView1.ReadOnly = true;
            Task.Run(() => {
                matlabPolt3 = new MatlabDll();
                supper.setInfo("组件加载成功.");
            });
        }

        public DataGridViewColumn AddColumn(string columnName, string dataPropertyName, int fillWeight = 100, DataGridViewContentAlignment alignment = DataGridViewContentAlignment.MiddleCenter, bool readOnly = true) {
            DataGridViewColumn column = new DataGridViewTextBoxColumn();
            column.HeaderText = columnName;
            column.DataPropertyName = dataPropertyName;
            column.Name = columnName;
            column.ReadOnly = readOnly;
            column.FillWeight = fillWeight;
            column.SortMode = DataGridViewColumnSortMode.NotSortable;
            column.DefaultCellStyle.Alignment = alignment;
            dataGridView1. Columns.Add(column);
            return column;
        }

        private void button2_Click(object sender, EventArgs e) {
            double[,] dd = new double[2, 3] { { 1, 2, 3 }, { 2, 3, 4 } };
            String[] leg = new String[3] { "asdf", "asdf", "asdf" };
            if (matlabPolt3 != null) {
                matlabPolt3.myPolt33((MWNumericArray)dd, (MWStringArray)leg, "s", "y", "t");
            } else {
                supper.setInfo("加载中请稍后试");
            }

         
        }

        private void button1_Click(object sender, EventArgs e) {
            var list = HttpSysUtil.getStat();
            if (list == null) {
                //this.ShowErrorTip("网络不稳定!");
                return;
            }
            dataGridView1.DataSource = list;
        }
    }
}
